package com.dps.omc.schedule;

import com.dps.omc.enumer.EnumJobState;
import com.dps.omc.model.Job;
import com.dps.omc.model.User;
import com.dps.omc.publish.JobManager;
import com.dps.omc.publish.TaskManager;
import com.dps.omc.service.IJobService;
import com.dps.omc.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lip on 2016-03-01.
 */
@Service
public class PlanRunTask extends BaseTask{
    @Autowired
    private IJobService jobService;
    @Autowired
    private ITaskService taskService;
    @Autowired
    private TaskManager taskManager;
    @Autowired
    private JobManager jobManager;
    public void execute() throws Exception {
        logInfo("PlanRunTask任务开始");
        List<Job> jobs = jobService.findList("status", EnumJobState.READY);
        User user = new User();
        user.setUserName("SYS");
        user.setRealName("SYS");
        for(Job job:jobs)
        {
            jobManager.runSchedule(job,user);
        }
        logInfo("PlanRunTask任务结束");
    }
}
